package com.athuiju.fenxiaoback.service.impl;

import com.alibaba.fastjson.TypeReference;
import com.athuiju.fenxiaoback.entity.UmsMemberReceiveAddress;
import com.athuiju.fenxiaoback.entity.WmsWareInfo;
import com.athuiju.fenxiaoback.entity.vo.FareVo;
import com.athuiju.fenxiaoback.entity.vo.MemberAddressVo;
import com.athuiju.fenxiaoback.mapper.WmsWareInfoMapper;
import com.athuiju.fenxiaoback.service.UmsMemberReceiveAddressService;
import com.athuiju.fenxiaoback.service.WmsWareInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Random;

/**
 * <p>
 * 仓库信息 服务实现类
 * </p>
 *
 * @author athuiju
 * @since 2021-07-06
 */
@Service
public class WmsWareInfoServiceImpl extends ServiceImpl<WmsWareInfoMapper, WmsWareInfo> implements WmsWareInfoService {

    @Autowired
    UmsMemberReceiveAddressService memberReceiveAddressService;

    @Override
    public FareVo getFare(Long addrId,String memberid) {

        QueryWrapper<UmsMemberReceiveAddress> addressQueryWrapper=new QueryWrapper<>();
        addressQueryWrapper.eq("member_id",memberid);
        addressQueryWrapper.eq("id",addrId);
        UmsMemberReceiveAddress info = memberReceiveAddressService.getOne(addressQueryWrapper);


        FareVo fareVo = new FareVo();
        if (info==null){
            fareVo.setCode(-1);
            return fareVo;
        }
        fareVo.setMemberReceiveAddress(info);
        if(info != null){
            String phone = info.getPhone();
            if(phone == null || phone.length() < 2){
                phone = new Random().nextInt(100) + "";
            }
            BigDecimal decimal = new BigDecimal(phone.substring(phone.length() - 1));
            fareVo.setFare(decimal);
        }else{
            fareVo.setFare(new BigDecimal("20"));
        }
        return fareVo;
    }
}
